<?php

namespace App\Api;


use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\Notice;
use Illuminate\Http\Request;

class NoticeController extends Controller
{

    public function index()
    {
        $notices = Notice::all();
        return $notices;
    }


    public function store(Request $request, Article $article)
    {
        $request->validate([
            'title' => ['required', 'min:3'],
            'content' => ['required', 'min:5'],
        ]);
        $house = $article->notices()->create($request->input());
        $house->extra = ['price' => $request->price, 'time' => $request->time];
        $house->save();
        return $this->message('发表成功', $house->toArray());
    }


    public function show(Article $article, Notice $notice)
    {
        return $notice;
    }


    public function update(Request $request, Article $article, Notice $notice)
    {
        $notice->update($request->input());
        return $this->message('更新成功', $notice->toArray());
    }

    public function destroy(Article $article, Notice $notice)
    {
        $notice->delete();
        return $this->message('删除成功');
    }
}
